package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * ClassName: GoodsTypeController
 * Description:
 * Date: 2022/1/15 22:02
 *
 * @version:
 * @since JDK 1.8
 */

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {



    @Autowired
    private GoodsTypeService goodsTypeService;
    @PostMapping("/loadGoodsType")
    public List<Map<String,Object>> loadGoodsType(){
        List<Map<String,Object>> GoodsTypeList = goodsTypeService.loadGoodsType(-1);
        return GoodsTypeList;
    }





    @PostMapping("/save")
    public ServiceVO saveGoodsType(String goodsTypeName,Integer pId){

        try{
            goodsTypeService.saveGoodsType(goodsTypeName,pId);
            return new ServiceVO<>(100,"请求成功");
        }catch(Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(100,"新增分类失败");

    }


    @PostMapping("/delete")
    public ServiceVO deleteGoodsType(Integer goodsTypeId){

        try{
            goodsTypeService.deleteGoodsType(goodsTypeId);
            return new ServiceVO<>(100,"请求成功");
        }catch(Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(100,"删除分类失败");

    }





}
